const { query } = require('express');
const express = require('express')
const app = express()


app.use(express.static('public'))



app.get ('/index',(req,res)=>{
    console.log(req.method);
    console.log(req.url);
    console.log(req.httpVersion);
    console.log(req.headers['host']);

    const{a,b} = req.query
    console.log('query参数',a,b)
    res.send('get 返回参数')
    
})
const allUsers = [
    {id:1,name:'tom',age:18},
    {id:2,name:'tom2',age:19},
    {id:3,name:'tom3',age:16}

]
app.get('/user/:id',(req,res)=>{
    const{id} = req.params
    const user = allUsers.find(user => user.id === +id)
    res.send(user)
})


app.post('/index', (req, res) => {
    console.log('处理 /index post请求')
    console.log('body参数', req.body)
    res.send('post 返回参数')
})
app.listen('8787',  () => {
    console.log('服务已启动: http://localhost:8787')
  })